{% extends "element/saas/base_mini.html" %}

{% block meta_title %}单点关联{% endblock %}

{% block main %}
    <style>
        #datagrid_tree .mini-tree-icon {
            display: none;
        }
        .mini-radiobuttonlist table label {
            vertical-align: initial;
        }
    </style>
    <div class="admin-content">
        <div id="toolbar1" class="mini-toolbar" style="padding: 2px 0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button mini-button-eltext" iconCls="icon-chart_organisation" plain="true">单点关联分析系统</a>
                        <span class="separator"></span>
                        <a class="mini-button" iconCls="icon-report10" plain="true" onclick="elreport('10')">全景版征信报告</a>
                        <a class="mini-button" iconCls="icon-report11" plain="true" onclick="elreport('11')">标准版报告</a>
                        <a class="mini-menubutton" iconCls="icon-pdf" plain="true" menu="#popupMenu3">下载报告PDF</a>
                        <a class="mini-button" iconCls="icon-feed_add" plain="true" onclick="">关注该企业</a></a>
                        <a class="mini-button" iconCls="icon-excel" plain="true" onclick="downloadSure()">导出结果为Excel</a>
                    </td>
                </tr>
            </table>
        </div>

        <ul id="popupMenu3" class="mini-menu" style="display:none;">
            <li iconCls="icon-pdf" onclick="elreportpdf('10')">全景版PDF</li>
            <li iconCls="icon-pdf" onclick="elreportpdf('11')">标准版PDF</li>
        </ul>

        <div style="padding-top:6px;">
            <div class="min-panel" style="float:left;width:100%;">
                <div id="mainTabs" class="mini-tabs" activeIndex="0" arrowPosition="side" showNavMenu="true"
                     height="auto">
                    <div title="单点关联搜索条件" name="主数据表" iconCls="icon-zoomin" height="auto">
                        {% include "element/saas/related/related_single_search.html" %}
                    </div>
                    <div title="可视化关联图谱" name="可视化关联图谱" iconCls="icon-chart_line" height="auto"
                         url="/report/yKF4Qme76ZV/tupu/?dstyle=2"></div>
                    <div title="搜索结果详情" name="搜索结果详情" iconCls="icon-table" height="auto">
                        {% include "element/saas/related/related_single_treetable.html" %}
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block footer_js %}
    <script type="text/javascript">
        var se_rddata = [
            {'value': '1', 'text': '向下（投资&任职）'},
            {'value': '2', 'text': '向下（投资）'},
            {'value': '3', 'text': '向下（任职）'},
            {'value': '4', 'text': '向上（股东）'}
        ];
        var se_sortindexData = [
            {'value': '0', 'text': '默认'},
            {'value': '1', 'text': '出资比例'},
            {'value': '2', 'text': '出资额'},
            {'value': 'REGCAP', 'text': '注册资金'},
            {'value': 'ESDATE', 'text': '开业日期'}
        ];
        var se_sortbydata = [
            {'value': 'desc', 'text': '降序'},
            {'value': 'asc', 'text': '升序'}
        ];
        var se_type = [
            {'value': '1', 'text': '企业（名称）'},
            {'value': '2', 'text': '企业（注册号）'},
            {'value': '3', 'text': '个人（身份证号）'},
            {'value': '4', 'text': '个人（姓名+公司名称）'}
        ];
        var radioval = 1;
        mini.parse();
        var grid_main = mini.get("datagrid_main");
        var tabs = mini.get("mainTabs");
        var tab = tabs.getTab("可视化关联图谱");
        var tab1 = tabs.getTab("搜索结果详情");
        var form_search = new mini.Form("se_form");
        top["win"] = window;
        var selecttype = mini.get("selecttype");
        selecttype.on("valuechanged", function (e) {
            $("#se_table .selecttype").hide();
            radioval = this.getValue();
            switch (radioval) {
                case "1":
                    showbox("combox1");
                    break;
                case "2":
                    showbox("combox2");
                    break;
                case "3":
                    showbox("personbox1");
                    break;
                case "4":
                    showbox("personbox2");
                    break;
            }
        });
        function showbox(id) {
            $("#" + id).show();
        }
        function elselectionchanged() {
            var entid_value = grid_tree.getSelected().entid;
            var entname_value = grid_tree.getSelected().entname;
            grid_main.load({entid: entid_value});
            $("#presentent").html(entname_value);
            tabs.activeTab(tabs.getTab("主数据表"));
        }
        $("#clearbtn").click(function () {
            $("#errorText").hide();
            form_search.reset();
        });
        var selectVal = "", nid = "";
        function formValid() {
            getVal();
            if (selectVal == "" || selectVal == "￥￥￥") {
                $("#errorText").show();
                $("#errorText .errorText").html("填写内容不能为空");
                return false;
            } else {
                $.ajax({
                    url: "/saas/related_node_check/?ntype=" + radioval + "&selectVal=" + selectVal,
                    type: "POST",
                    success: function (response) {
                        var st = response.status;
                        var msg = response.msg;
                        if (st == "success") {
                            $("#errorText").hide();
                            nid = msg;
                            return true;
                        } else {
                            $("#errorText").show();
                            if (msg == "") {
                                $("#errorText .errorText").html("没有找到相关主体");
                            } else {
                                $("#errorText .errorText").html(msg);
                            }
                            return false;
                        }
                    }
                });
            }
        }
        function getVal() {
            if (radioval == 1) {
                selectVal = mini.getbyName("ENTNAME").getValue();
            }
            if (radioval == 2) {
                selectVal = mini.getbyName("REGNO").getValue();
            }
            if (radioval == 3) {
                selectVal = mini.getbyName("CERNO").getValue();
            }
            if (radioval == 4) {
                selectVal = mini.getbyName("ENTNAME1").getValue() + "￥￥￥" + mini.getbyName("PNAME").getValue();
            }
        }
        function Adsearch() {
            formValid();
            var n1 = $("#errorText").css("display") == "none";
            if (n1) {
                form_search.validate();
                if (form_search.isValid() == false) return;
                var url = '/saas/single/' + '?ntype=' + radioval + "&pk=" + nid + "&relationdirection=" + mini.getbyName("relationdirection").getValue() + "&region_id=" + mini.getbyName("region_id").getValue()
                        + "&nic_id=" + mini.getbyName("nic_id").getValue() + "&ENTSTATUS=" + mini.getbyName("ENTSTATUS").getValue() + "&REGCAP1=" + mini.getbyName("REGCAP1").getValue()
                        + "&REGCAP2=" + mini.getbyName("REGCAP2").getValue() + "&ESDATE1=" + mini.getbyName("ESDATE1").getValue() + "&ESDATE2=" + mini.getbyName("ESDATE2").getValue();
                tabs.loadTab(url, tab);
                tabs.activeTab(tab);
            }
        }
        function elreport(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择搜索结果中的一个企业");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                if (entid_value) {
                    var entname_value = grid_main.getSelected().nodename;
                    newtab("报告: " + entname_value, '/report/' + entid_value + '/?version=' + a, 'icon-report' + a);
                }
                else {
                    mini.alert("请选择搜索结果中的一个企业");
                }
            }
        }
        {#        //tab height#}
        function tabhei(tab) {
            tab.onload = function () {
                var iframe = tabs.getTabIFrameEl(tab);
                var hei = iframe.contentWindow.document.body.scrollHeight + 150;
                iframe.style.height = hei + 'px';
            };
        }
        function elreportpdf(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择搜索结果中的一个企业");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                if (entid_value) {
                    window.open("/reportpdf/" + entid_value + '/?version=' + a);
                }
                else {
                    mini.alert("请选择搜索结果中的一个企业");
                }
            }
        }

        function eltupu() {
            var entid_value = grid_tree.getSelected().entid;
            var entname_value = grid_tree.getSelected().entname;
            newtab("关系图谱: " + entname_value, '/report/' + entid_value + '/tupu/', 'icon-charts');
        }

        function elroad() {
            var entid_value = grid_tree.getSelected().entid;
            var entname_value = grid_tree.getSelected().entname;
            newtab("路径图: " + entname_value, '/report/' + entid_value + '/road/', 'icon-poll');
        }
        // 页面json数据生成excel表
        function downloadSure() {
            tabs.setActiveIndex(2);
            var data = grid_main.getList();
            if (!data.length) {
                mini.alert("请重新输入搜索条件~");
                tabs.setActiveIndex(0);
            } else {
                var dataval = grid_main.getCheckedNodes();
                if (dataval.length) {
                    JSONToExcelConvertor(dataval);
                } else {
                    mini.alert("请选择要下载的路径~");
                }
            }
        }
        function JSONToExcelConvertor(JSONData) {
            var FileName = "单点关联筛查结果-{{ sitesettings.website_name }}-" + gettime();
            //先转化json
            var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
            var headers = {
                "entname": "企业名称",
                "relation": "关系类型",
                "SUBCONAM": "出资额(万)",
                "CURRENCY": "出资币种",
                "FUNDEDRATIO": "出资比例",
                "CONDATE": "出资日期",
                "name": "相关人",
                "POSITION_A": "前者任职",
                "POSITION_B": "后者任职",
                "gender": "相关人性别",
                "nativeplace": "相关人户籍",
                "birthyear": "相关人出生年份",
                "region": "所在地",
                "regcapital_amount": "注册资本(万)",
                "legalperson_name": "法人",
                "opendate": "开业日期",
                "staffnum": "员工人数",
                "eststatus": "经营状态",
                "regadd": "企业地址",
                "nic": "所属行业",
                "revenue": "营业收入(万)",
                "total_profit": "利润总额(万)"
            };
            var arrKey = ["entname", "relation", "SUBCONAM", "CURRENCY", "FUNDEDRATIO", "CONDATE", "name", "POSITION_A", "POSITION_B", "gender", "nativeplace",
                "birthyear", "region", "regcapital_amount", "legalperson_name", "opendate", "staffnum", "eststatus", "regadd", "nic", "revenue", "total_profit"];
            if (arrData[0]["entname"] != "企业名称") {
                arrData.unshift(headers);
            }
            if (isIEexcel()) {
                exportExcelIE(arrData, arrKey, FileName);
            } else {
                downloadExl(arrData, arrKey, FileName);
            }
        }
    </script>
    {{ block.super }}
{% endblock %}
